#include "discipline.h"

#include <QHash>

#include "database.h"

Discipline::Discipline()
{
}

bool Discipline::operator==(const Discipline &other) const
{
  return _name == other._name;
}

bool Discipline::operator<(const Discipline &other) const
{
  return _name < other._name;
}

QList<Talent> Discipline::talents(int circle) const
{
  return _circles[circle-1]._talents.keys();
}

QMap<ed::Characteristic, int> Discipline::bonuses(int circle) const
{
  return _circles[circle-1]._bonuses;
}

int Discipline::karmaBonus(int circle) const
{
  return _circles[circle-1]._karmaBonus;
}

QStringList Discipline::karmaUsages(int circle) const
{
  return _circles[circle-1]._karmaUsages;
}

bool Discipline::isDiscipline(const Talent &t) const
{
  foreach(const Circle& c, _circles)
  {
    if (c._talents.contains(t)) return c._talents[t];
  }
  return false;
}

QList<Specialization> Discipline::specializations() const
{
  QList<Specialization> result;
  foreach(const Specialization& s, Database::specializations())
  {
    if (s.discipline() == name()) result << s;
  }
  return result;
}

int Discipline::talentCircle(const Talent &t) const
{
  int result = 1;
  foreach(const Circle& c, _circles)
  {
    if (c._talents.contains(t)) return result;
    ++result;
  }
  Q_ASSERT(false);
  return -1;
}

Discipline::operator QString() const
{
  return _name + "(Discipline)";
}


uint qHash(const Discipline &discipline)
{
  return qHash(discipline.name());
}
